import $http from "@/services";
export default {
    state: {
        rewAndPubLists: [],
        rewAndPubTotal: 0,
        rewAndPubDetail: null,
        rewAndPubSearch: {
            page: 1,
            size: 5,
            queryData: {}
        }
    },
    // 赋值
    reducers: {
        setRewAndPubLists(state, { payload }) {
            return { ...state, rewAndPubLists: payload }
        },
        setRewAndPubTotal(state, { payload }) {
            return { ...state, rewAndPubTotal: payload }

        },
        setRewAndPubDetail(state, { payload }) {
            return { ...state, rewAndPubDetail: payload }
        },
        setRewAndPubSearch(state, { payload }) {
            return { ...state, rewAndPubSearch: { ...state.rewAndPubSearch, ...payload } };
        }
    },
    effects: {
        // 初始化数据，获取数据
        *initRewAndPubContent({ payload }, { put, call, select }) {
            // 重新处理请求关系
            yield put({
                type: "setRewAndPubSearch",
                payload
            })
            const { rewAndPubSearch } = yield select(state => state.rewardAndPunishment);
            //请求数据
            const { data, msg } = yield call($http.getrewardAndPunishmentList, rewAndPubSearch);

            yield put({
                type: "setRewAndPubLists",
                payload: data.list
            })
            yield put({
                type: "setRewAndPubTotal",
                payload: data.total
            })

        },
        // 重新获取职级详情
        *getDetailRewAndPub({ payload }, { put, call }) {
            const { data } = yield call($http.getRewardAndPunishmentDetail, payload);
            console.log(data)
            if (data) {
                yield put({
                    type: "setRewAndPubDetail",
                    payload: data
                })
                yield put({
                    type: "common/setIsShowDetail",
                    payload: true
                });
            }

        }
    }
}